package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.GlueAdhesive;
import com.ruoyi.system.mapper.GlueAdhesiveMapper;
import com.ruoyi.system.service.IGlueAdhesiveService;
import com.ruoyi.system.service.IGlueCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * 胶粘剂信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@Service
public class GlueAdhesiveServiceImpl extends ServiceImpl<GlueAdhesiveMapper,GlueAdhesive> implements IGlueAdhesiveService
{
    @Autowired
    private GlueAdhesiveMapper glueAdhesiveMapper;

    @Autowired
    private IGlueCategoryService glueCategoryService;

    /**
     * 查询胶粘剂信息
     *
     * @param id 胶粘剂信息主键
     * @return 胶粘剂信息
     */
    @Override
    public GlueAdhesive selectGlueAdhesiveById(Long id)
    {
        return glueAdhesiveMapper.selectGlueAdhesiveById(id);
    }

    /**
     * 查询胶粘剂信息列表
     *
     * @param glueAdhesive 胶粘剂信息
     * @return 胶粘剂信息
     */
    @Override
    public List<GlueAdhesive> selectGlueAdhesiveList(GlueAdhesive glueAdhesive)
    {
        //有值就递归查出所有子集
        if (!ObjectUtils.isEmpty(glueAdhesive.getClassifyId())){
            List<Long> ids = glueCategoryService.getIds(glueAdhesive.getClassifyId());
            glueAdhesive.setClassifyIds(ids);
        }

        return glueAdhesiveMapper.selectGlueAdhesiveList(glueAdhesive);
    }

    /**
     * 新增胶粘剂信息
     *
     * @param glueAdhesive 胶粘剂信息
     * @return 结果
     */
    @Override
    public int insertGlueAdhesive(GlueAdhesive glueAdhesive)
    {
        glueAdhesive.setCreateTime(DateUtils.getNowDate());
        glueAdhesive.setCreateBy(SecurityUtils.getUserId().toString());
        return glueAdhesiveMapper.insertGlueAdhesive(glueAdhesive);
    }

    /**
     * 修改胶粘剂信息
     *
     * @param glueAdhesive 胶粘剂信息
     * @return 结果
     */
    @Override
    public int updateGlueAdhesive(GlueAdhesive glueAdhesive)
    {
        glueAdhesive.setUpdateTime(DateUtils.getNowDate());
        return glueAdhesiveMapper.updateGlueAdhesive(glueAdhesive);
    }

    /**
     * 批量删除胶粘剂信息
     *
     * @param ids 需要删除的胶粘剂信息主键
     * @return 结果
     */
    @Override
    public int deleteGlueAdhesiveByIds(Long[] ids)
    {
        return glueAdhesiveMapper.deleteGlueAdhesiveByIds(ids);
    }

    /**
     * 删除胶粘剂信息信息
     *
     * @param id 胶粘剂信息主键
     * @return 结果
     */
    @Override
    public int deleteGlueAdhesiveById(Long id)
    {
        return glueAdhesiveMapper.deleteGlueAdhesiveById(id);
    }


    /**
     * 胶黏剂型号三级目录
     * @param dto
     * @return
     */
    @Override
    public List<String> getModel(String dto) {
       return glueAdhesiveMapper.getModel(dto);

    }
}
